from PyQt5.Qt import *

import sys


class widget(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("3333")
        self.resize(500, 500)
        self.setup_ui()

    def setup_ui(self):
        self.lable = QLabel(self)
        self.lable.setText("111")

        self.btn1 = QPushButton(self)
        self.btn1.setText("回主控件")
        self.btn1.move(100, 100)
        self.btn1.clicked.connect(self.close)

    def closeEvent(self, event):
        print("Child window is closed")
        event.accept()  # 关闭子窗口


class widget1(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("4444")
        self.resize(500, 500)
        self.setup_ui()

    def setup_ui(self):
        self.lable = QLabel(self)
        self.lable.setText("222")

        self.btn1 = QPushButton(self)
        self.btn1.setText("回主控件")
        self.btn1.move(100, 100)
        self.btn1.clicked.connect(self.close)

    def closeEvent(self, event):
        print("Child window is closed")
        event.accept()  # 关闭子窗口


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("")
        self.resize(500, 500)
        self.setup_ui()


    def setup_ui(self):
        self.btn1 = QPushButton(self)
        self.btn1.setText("控件1")
        self.btn1.move(100, 100)
        self.btn1.clicked.connect(self.zhuong1)

        self.btn2 = QPushButton(self)
        self.btn2.setText("控件2")
        self.btn2.move(100, 140)
        self.btn2.clicked.connect(self.zhuong2)


    def zhuong1(self):
        self.w1 = widget()
        self.w1.show()

    def zhuong2(self):
        self.w1 = widget1()
        self.w1.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = Window()
    win.show()
    sys.exit(app.exec_())
